package pers.supeijin.devtools.converter.base;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
import com.intellij.psi.XmlElementFactory;
import com.intellij.psi.util.PsiUtilBase;
import com.intellij.psi.xml.XmlTag;

import pers.supeijin.devtools.converter.utils.CommonUtils;
import pers.supeijin.devtools.utils.GeneralContext;

public abstract class BaseConverter {
	protected Project mProject;
	protected VirtualFile mVirtualFile;
	protected XmlElementFactory mXmlElementFactory;
	protected PsiFile mPsiFile;
	protected GeneralContext mGeneralContext;
	public BaseConverter(GeneralContext generalContext, VirtualFile virtualFile) {
		mGeneralContext=generalContext;
		this.mProject = generalContext.getProject();
		this.mVirtualFile = virtualFile;
		mXmlElementFactory= XmlElementFactory.getInstance(generalContext.getProject());
		PsiFile psiFile = PsiUtilBase.getPsiFile(generalContext.getProject(), virtualFile);
		//创建编辑的副本，以免影响原来的版本。
		mPsiFile= CommonUtils.copyFile(mProject,psiFile);
	}

	protected final XmlTag getXmlTag(String tagText){
		return mXmlElementFactory.createHTMLTagFromText(tagText);
	}

}
